//
//  UIAlertController+Category.m
//  VICategory
//
//  Created by lan's Mac on 2022/7/4.
//

#import "UIAlertController+Category.h"

@implementation UIAlertController (Category)

+ (void)showWithViewController:(UIViewController *)viewController
                         title:(NSString *)titleStr
                      btnTitle:(NSString *)btnTitle
                      clickBtn:(AlertControllerBlock)btnAction {
    [self showWithViewController:viewController title:titleStr message:@"" btnTitle:btnTitle clickBtn:btnAction];
}

+ (void)showWithViewController:(UIViewController *)viewController
                       message:(NSString *)message
                      btnTitle:(NSString *)btnTitle
                      clickBtn:(AlertControllerBlock)btnAction {
    [self showWithViewController:viewController title:@"" message:message btnTitle:btnTitle clickBtn:btnAction];
}

+ (void)showWithViewController:(UIViewController *)viewController
                         title:(NSString *)titleStr
                       message:(NSString *)message
                      btnTitle:(NSString *)btnTitle
                      clickBtn:(AlertControllerBlock)btnAction {
    [self showWithViewController:viewController title:titleStr message:message leftBtnTitle:btnTitle rightBtnTitle:@"" clickLeftBtn:btnAction clickRightBtn:nil];
}

+ (void)showWithViewController:(UIViewController *)viewController
                        title:(NSString *)titleStr
                 leftBtnTitle:(NSString *)leftTitle
                rightBtnTitle:(NSString *)rightTitle
                 clickLeftBtn:(AlertControllerBlock)leftAction
                 clickRightBtn:(AlertControllerBlock)rightAction {
    [self showWithViewController:viewController title:titleStr message:@"" leftBtnTitle:leftTitle rightBtnTitle:rightTitle clickLeftBtn:leftAction clickRightBtn:rightAction];
}

+ (void)showWithViewController:(UIViewController *)viewController
                      message:(NSString *)message
                 leftBtnTitle:(NSString *)leftTitle
                rightBtnTitle:(NSString *)rightTitle
                 clickLeftBtn:(AlertControllerBlock)leftAction
                 clickRightBtn:(AlertControllerBlock)rightAction {
    [self showWithViewController:viewController title:@"" message:message leftBtnTitle:leftTitle rightBtnTitle:rightTitle clickLeftBtn:leftAction clickRightBtn:rightAction];
}

+ (void)showWithViewController:(UIViewController *)viewController
                         title:(NSString *)titleStr
                       message:(NSString *)message
                  leftBtnTitle:(NSString *)leftTitle
                 rightBtnTitle:(NSString *)rightTitle
                  clickLeftBtn:(AlertControllerBlock)leftAction
                 clickRightBtn:(AlertControllerBlock)rightAction {
    
    UIAlertController *alert = [UIAlertController alertControllerWithTitle:titleStr message:message preferredStyle:UIAlertControllerStyleAlert];
    
    if (leftTitle.length) {
        UIAlertAction *leftAlert = [UIAlertAction actionWithTitle:leftTitle style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            if (leftAction) {
                leftAction(nil);
            }
        }];
        [alert addAction:leftAlert];
    }
    
    if (rightTitle.length) {
        UIAlertAction *rightAlert = [UIAlertAction actionWithTitle:rightTitle style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            if (rightAction) {
                rightAction(nil);
            }
        }];
        [alert addAction:rightAlert];
    }
    
    [viewController presentViewController:alert animated:YES completion:nil];
}

+ (void)showWithViewController:(UIViewController *)viewController
                         title:(NSString *)titleStr
                       message:(NSString *)message
                  leftBtnTitle:(NSString *)leftTitle
                 rightBtnTitle:(NSString *)rightTitle
                     leftColor:(UIColor *)leftColor
                    rightColor:(UIColor *)rightColor
                  clickLeftBtn:(AlertControllerBlock)leftAction
                 clickRightBtn:(AlertControllerBlock)rightAction {
    
    UIAlertController *alert = [UIAlertController alertControllerWithTitle:titleStr message:message preferredStyle:UIAlertControllerStyleAlert];
    
    if (leftTitle.length) {
        UIAlertAction *leftAlert = [UIAlertAction actionWithTitle:leftTitle style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            if (leftAction) {
                leftAction(nil);
            }
        }];
        [alert addAction:leftAlert];
        if(leftColor) [leftAlert setValue:leftColor forKey:@"titleTextColor"];
    }
    
    if (rightTitle.length) {
        UIAlertAction *rightAlert = [UIAlertAction actionWithTitle:rightTitle style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            if (rightAction) {
                rightAction(nil);
            }
        }];
        [alert addAction:rightAlert];
        if(rightColor) [rightAlert setValue:rightColor forKey:@"titleTextColor"];
    }
    
    [viewController presentViewController:alert animated:YES completion:nil];
}


@end
